<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/react@17/umd/react.production.min.js" rel="external nofollow" rel="external nofollow"></script>

    <script src="https://unpkg.com/react-dom@17/umd/react-dom.production.min.js" rel="external nofollow" rel="external nofollow"></script>

    <script src="https://unpkg.com/babel-standalone@6/babel.min.js" rel="external nofollow" rel="external nofollow"></script>
</head>
<body>
    <div id="test"></div>
    <script type="text/babel">
        // 创建组件
        class Weather extends React.Component{
            // 构造器调用几次？1次
            constructor(props){
                super(props);
                this.state={isHot:false}
                this.demo=this.demo.bind(this)
            }
            // render调用几次？   1+n次
            render(){
                console.log(this);
                const{isHot}=this.state;
                return <h1 onClick={this.demo}>今天天气很{isHot?'炎热':'凉爽'}</h1>
            }
            demo(){
                // alert('----');
                // console.log(this.setState());
            //    return this.state.isHot?'false':'true'
            const isHot=this.state.isHot
            // 状态必须通过(setstate)进行更新,且更新是一种合并,不是替换
            this.setState({isHot:!isHot});
            }
        }
        ReactDOM.render(<Weather/>,document.getElementById('test'))
        // function demo(){
// alert('----');
        // }
    </script>
</body>
</html>